<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
  String xm = this.getServletContext().getInitParameter("path");
	String path1 = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/"+xm;
%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加销售机会信息</title>
<link href="<%=path1%>/css/css.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=path1%>/scripts/jquery-1.7.2.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/jquery-1.7.2.min.js"></script>
<script type="text/javascript"
	src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/jquery.jqGrid.src.js"></script>
<script type="text/javascript"
	src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/i18n/grid.locale-cn.js"></script>
<script type="text/javascript"
	src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/jquery.jqGrid.min.js"></script>

<!--[if IE 6]>
<script type="text/javascript" src="js/ie6png.js" ></script>
<script type="text/javascript">
DD_belatedPNG.fix('div,ul,li,a,p,img,body,dl,dt,dd');</script>
<![endif]-->
    <script type="text/javascript" src="js/autoTrain.js" charset="UTF-8"></script>
<script type="text/javascript">
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
</script>
<!-- 项目、楼栋、单元、房间查询 -->
<script type="text/javascript">
$(document).ready(function(){
	selectProject();
});
</script>

<script type="text/javascript">
<!--项目-->
function selectProject(){
	var SearchSql;
		$.ajax({
	    	url:"./ht/project/selectAll1.do",
	        datatype:'json', 
	        //data:{'SearchSql':SearchSql}, // 发送数据   
	        error:function(data){  
	            alert("出错了！！");  
	       },  
	       success:function(data){
           //  alert("12132");
	       	var len=data.rows.length;
	       	//alert(len);
	        var select = document.getElementById("project");
	        //alert(select.value);
	       	if(len>0){
	       	
	           	for(var i=0;i<=len;i++){
	           		select.options.add(new Option(data.rows[i].project_name, data.rows[i].project_id)); 
	           	}

	       	}else{
	       		alert("项目不存在！！！");
	       	}
	       	
	       }
	 
	        });
	}
<!--楼栋 -->	
function selectbuild(){
	var SearchSql;
	var project= $("#project").val();
	
	if(project!=""){
		SearchSql=" and project_id='"+project+"'";

		$.ajax({
	    	url:"ht/build/selectBySql.do",
	        datatype:'json', 
	        data:{'SearchSql':SearchSql}, // 发送数据   
	        error:function(data){  
	            alert("出错了！！");  
	       },  
	       success:function(data){

	       	var len=data.rows.length;
	        var select = document.getElementById("build");
	       	if(len>0){
	       		
	           	for(var i=0;i<=len;i++){
	           		select.options.add(new Option(data.rows[i].build_name, data.rows[i].build_id)); 
	           	}

	       	}else{
	       		alert("不存在这个楼栋！！！");
	       	}
	       	
	       }
	 
	        });
	   }
	}
	
<!--单元 -->	
function selectUnit(){
	var SearchSql;
	var build= $("#build").val();

	if(build!=""){
		SearchSql=" and build_id='"+build+"'";
         alert(SearchSql);
		$.ajax({
	    	url:"ht/unit/SelectBySql.do",
	        datatype:'json', 
	        data:{'SearchSql':SearchSql}, // 发送数据   
	        error:function(data){  
	            alert("出错了！！");  
	       },  
	       success:function(data){
	     
	       	var len=data.rows.length;

	        var select = document.getElementById("unit");
	       	if(len>0){
	       		
	           	for(var i=0;i<=len;i++){
	           		select.options.add(new Option(data.rows[i].unit_code, data.rows[i].unit_id)); 
	           	}
	          
	       	}else{
	       		alert("不存在这个单元！！！");
	       	}
	       	
	       }
	 
	        });
	   }
	}
<!--房间 -->	
function selectRoom(){
	var SearchSql;
	var unit= $("#unit").val();
	if(build!=""){
		SearchSql=" and unit_id='"+unit+"'";
	
		alert("ceach:"+SearchSql);
		$.ajax({
	    	url:"ht/room/selectBySql.do",
	        datatype:'json', 
	        data:{'SearchSql':SearchSql}, // 发送数据   
	        error:function(data){  
	            alert("出错了！！");  
	       },  
	       success:function(data){
	     
	       	var len=data.rows.length;
	        var select = document.getElementById("room");
	       	if(len>0){
	       		
	           	for(var i=0;i<=len;i++){
	           		select.options.add(new Option(data.rows[i].room_code, data.rows[i].room_id)); 
	           	}
	           
	       	}else{
	       		alert("不存在这个房间！！！");
	       		
	       	}
	       	
	       }
	 
	        });
	   }
	}
</script>
<script type="text/javascript">

//添加
    function ajaxPost(){

    	var receive={
    		intention_description:$("#intention_description").val(),
    		customer_id:$("#customer_id").val(),
    		customer_name:$("#customer_name").val(),
    		tel:$("#tel").val(),
    		user_id:$("#user_id").val(),
    		user_name:$("#user_name").val(),
    		project_id:$("#project").val(),
    		build_id:$("#build").val(),
    		unit_id:$("#unit").val(),
    		room_id:$("#room").val(),
    		number:$("#number").val(),
    		sale_chance_name:$("#sale_chance_name").val()
    	};
    	
        $.ajax({ 	
        data: receive,
        type:"Post",  
        dataType: 'json',  
        url:"./Sale_Chance/addSale_Chance.do", 
        error:function(data){  
             alert("出错了！！");  
        },  
        success:function(data){
        	alert('销售机会添加成功！');
        	window.location.href = 'listSale_Chance.jsp'; 
         }  
         });  
     } 
    // 重置
    function ajaxReset(){

    
    	$("#intention_description").val(""),
		$("#customer_id").val(""),
		$("#customer_name").val(""),
		$("#tel").val(""),
		$("#user_id").val(""),
		$("#user_name").val(""),
		$("#project").val(""),
		$("#build").val(""),
		$("#unit").val(""),
		$("#room").val(""),
		$("#sale_chance_name").val("")
    }
</script>
<!-- 验证 -->
<script type="text/javascript">
   function checkintention_description(){
	  var intention_description= $("#intention_description").val();
	  if(intention_description==""){
		 alert("意向描述不能为空！"); 
		 $("#intention_description").focus();
		 return false;
	  }
	  return true;
   }
   
   function checkNumber(){
		  var number= $("#number").val();
		  if(number==""){
			 alert("业务员编号不能为空！"); 
			 $("#number").focus();
			 return false;
		  }
		  return true;
	   }
   
   function checkcustomer_name(){
		  var customer_name= $("#customer_name").val();
		  if(customer_name==""){
			 alert("客户姓名不能为空！"); 
			 $("#customer_name").focus();
			 return false;
		  }
		  return true;
	   }
   
   function checkRoom(){
		  var room= $("#room").val();
		  if(room==""){
			 alert("意向房间不能为空！"); 
			 $("#room").focus();
			 return false;
		  }
		  return true;
	   }
   function checksale_chance_name(){
		  var sale_chance_name= $("#sale_chance_name").val();
		  if(sale_chance_name==""){
			 alert("机会名称不能为空！"); 
			 $("#sale_chance_name").focus();
			 return false;
		  }
		  return true;
	   }
   
   function checkAll(){
		  return checkintention_description()&&checkNumber()&&checkcustomer_name()&&checkRoom()&&checksale_chance_name();
	   }
</script>
<!-- 查询 -->
<script type="text/javascript">
function select(){
var SearchSql;
var number= $("#number").val();
alert(number);
if(number!=""){
	SearchSql="and number='"+number+"'";
}

	alert("ceach:"+SearchSql);
	$.ajax({
    	url:"ht/selectBySql.do",
        datatype:'json', 
        data:{'SearchSql':SearchSql}, // 发送数据   
        error:function(data){  
            alert("出错了！！");  
       },  
       success:function(data){
    	$("#user_id").val(data.rows[0].user_id)
       	var len=data.rows.length;
       	alert("namber:"+data.rows.length);
       	if(len>0){

           	$("#user_id").val(data.rows[0].user_id),
           	$("#user_name").val(data.rows[0].name)
       	}else{
       		alert("这个业务员不存在！！！");
       		$("#number").val("");
       		$("#user_name").val("");
       		$("#number").focus();
       	}
       	
       }
 
        });
}

function selectcustomer_name1(){
	var SearchSql;
	var customer_name= $("#customer_name").val();
	if(customer_name!=""){
		SearchSql="and customer_name='"+customer_name+"'";
		alert("ceach:"+SearchSql);
		$.ajax({
	    	url:"./Customer/selectBySala.do",
	        datatype:'json', 
	       
	        data:{'page':10,'rows':1,'Search':SearchSql}, // 发送数据   
	        error:function(data){  
	            alert("出错了！！");  
	       },  
	       success:function(data){
	
	       	var len=data.rows.length;
	        var select = document.getElementById("tel");
	        $("#customer_id").val(data.rows[0].customer_id)
	       	if(len>0){
	       	
	           	for(var i=0;i<=len;i++){
	           		select.options.add(new Option(data.rows[i].tel, data.rows[i].tel)); 
	           	}

	       	}else{
	       		alert("这个客户不存在！！！");
	       		$("#customer_name").val("");
	       		$("#customer_name").focus();
	       	}
	       	
	       }
	 
	        });
	}
}
</script>

</head>
<body>
	<div class="yboxwidth boxcenter">
		<div class="ybox09">
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td style="padding-left: 20px"><table border="0"
							cellspacing="0" cellpadding="0">
							<tr valign="top">
								<td class="ybox11td5"></td>
								<td class="ybox11td6">填写销售机会</td>
								<td class="ybox11td7"></td>
								<td class="ybox11td2"></td>
								<td class="ybox11td3"></td>
								<td class="ybox11td2"></td>
								<td class="ybox11td3"></td>
								<td class="ybox11td2"></td>
								<td class="ybox11td4"></td>
							</tr>
						</table></td>
				</tr>
			</table>
		</div>
		<div class="ybox02">
			<table width="100%" border="0" cellspacing="0" cellpadding="0"
				class="margb4">
				<tr>
					<td class="ybox03td1"></td>
					<td class="ybox03td2"></td>
					<td class="ybox03td3"></td>
				</tr>
				<tr>
					<td class="ybox03td4"></td>
					<td class="ybox03td5"><div class="ybox05 margb8">
							<dl>
								<dt>
									<strong>销售机会信息</strong>
								</dt>
							</dl>
							<input type="hidden" id="user_id" />
							 <input type="hidden" id="customer_id" />
						</div>
						<table width="100%" border="0" cellpadding="0" cellspacing="1"
							class="ybox04table">
							<tr>
								<td width="9%" class="ybox04tdl"><span class="red">*</span>机会名称</td>
								<td width="15%" class="ybox04tdr" colspan="8"><input
									type="text" name="sale_chance_name" id="sale_chance_name"
									class="black12" style="width: 90%;" /></td>

							</tr>
							<tr>
								<td width="9%" class="ybox04tdl"><span class="red">*</span>意向项目</td>
								<td width="15%" class="ybox04tdr"><select id="project"
									style="width: 150px" onchange="selectbuild()">
										<option value=""></option>
								</select></td>
								<td width="9%" class="ybox04tdl"><span class="red">*</span>意向楼栋</td>
								<td width="15%" class="ybox04tdr"><select id="build"
									style="width: 150px" onchange="selectUnit()">
										<option value=""></option>
								</select></td>
								<td width="9%" class="ybox04tdl"><span class="red">*</span>意向单元</td>
								<td width="15%" class="ybox04tdr"><select id="unit"
									style="width: 150px" onchange="selectRoom()">
										<option value=""></option>
								</select></td>
								<td width="9%" class="ybox04tdl"><span class="red">*</span>意向房间</td>
								<td width="15%" class="ybox04tdr"><select id="room"
									style="width: 150px">
										<option value=""></option>
								</select></td>
							</tr>
						</table></td>
					<td class="ybox03td6"></td>
				</tr>
				<tr>
					<td class="ybox03td4"></td>
					<td class="ybox03td5">
						<table width="100%" border="0" cellpadding="0" cellspacing="1"
							class="ybox04table">
							<tr>
								<td width="9%" class="ybox04tdl"><span class="red">*</span>客户姓名</td>
								<td width="15%" class="ybox04tdr">
								<input id="customer_name" name="customer_name" type="text" class="black12"style="width: 90%;" " />
								<div id="sdiv"></div>
								</td>
								
								<td width="9%" class="ybox04tdl">客户联系方式</td>
								<td width="15%" class="ybox04tdr">
								<input type="text" id="tel"style="width: 150px">
								</input></td>

								<td width="9%" class="ybox04tdl"><span class="red">*</span>业务员编号</td>
								<td width="15%" class="ybox04tdr"><input name="number"
									type="text" class="black12" id="number" style="width: 80%;" />
									<img src="images/select.gif" style="cursor: pointer;"
									onclick="select()" /></td>
								<td width="9%" class="ybox04tdl">业务员姓名</td>
								<td width="15%" class="ybox04tdr"><input name="user_name"
									type="text" class="black12" id="user_name" style="width: 90%;"
									disabled="disabled" /></td>
							</tr>
							<tr>
								<td width="9%" class="ybox04tdl" style="padding-bottom: 65px"><span
									class="red">*</span> 意向描述</td>
								<td width="15%" class="ybox04tdr" colspan="7"><textarea
										rows="5" cols="150" name="intention_description"
										id="intention_description"></textarea></td>

							</tr>
							<tr>
								<td class="ybox04tdr" colspan="8">
									<dl>
										<!-- 标注 -->
										<dt>
											<strong></strong> </br>

										</dt>
									</dl>
								</td>
							</tr>

						</table>
					</td>
					<td class="ybox03td6"></td>
				</tr>
				<tr>
					<td class="ybox03td7"></td>
					<td class="ybox03td8"></td>
					<td class="ybox03td9"></td>
				</tr>
			</table>
			<table width="380" border="0" align="center" cellpadding="0"
				cellspacing="0">
				<tr>
					<td height="60" align="center"><img
						src="images/bottoncommit.gif" style="cursor: pointer;" width="95"
						height="34" onclick="return checkAll()&&ajaxPost()" /></td>
					<td height="60" align="center"><img
						src="images/bottonreset.gif" style="cursor: pointer;" width="95"
						height="34" onclick="ajaxReset()" /></td>
				</tr>
			</table>
		</div>
	</div>
</body>
</html>
